package stream;


import java.io.*;

import com.sun.xml.internal.ws.util.ByteArrayBuffer;


import channel.Channel;


public class Stream {
	
	public static void main(String[] args) throws ClassNotFoundException, IOException {
		A a = new A();
		a.a = 5;
		a.b = 1;
		a.c = 2;
		ObjectInputStream input = new ObjectInputStream(getStream(a));
		System.out.println(input.available());
		A b = new A();
		System.out.println(b);
		b = (A) input.readObject();
		System.out.println(b);
	}
	
	static public InputStream getStream(Channel object) {
		
		try {
			
			ByteArrayBuffer buffer = new ByteArrayBuffer();
			
			ObjectOutputStream output = new ObjectOutputStream(buffer);
			output.writeObject(object);
			output.flush();
			output.close();
			
			return buffer.newInputStream();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}
	
}

class A implements Channel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int a;
	int b;
	int c;
	
	public A() {
		a = b = c = 1;
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return a + "  " + b + "  " + c;
	}

	@Override
	public int THIS() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void THAT() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getType() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public InputStream toStream() {
		// TODO Auto-generated method stub
		return null;
	}

}
